package com.vitaf.cash.app.ui.dialog

import android.content.Context
import android.text.SpannableString
import android.view.LayoutInflater
import android.view.View
import com.vitaf.cash.app.common.VitafComDlog
import com.vitaf.cash.app.databinding.VitafDlogTipsBinding

/**
 * GombeCredit
 * @Author wwdeng
 * @CreateTime: 2024/11/13 15:41
 * @Annotation：提示dialog
 */
class VitafTipsDlog: VitafComDlog {

    private lateinit var binding: VitafDlogTipsBinding
    private var mCallback: IDialogCallback? = null

    override val pageName: String = "Tips"

    constructor(context: Context) : super(context) {}
    constructor(context: Context, callback: IDialogCallback?) : super(context) {
        mCallback = callback
    }

    constructor(context: Context, remark: String) : super(context) {
        pageRemark = remark
    }
    constructor(context: Context, remark: String, callback: IDialogCallback?) : super(context) {
        mCallback = callback
        pageRemark = remark
    }

    /**
     * 设置点击回调
     */
    fun setOnClick(callback: IDialogCallback){
        this.mCallback = callback
    }

    override fun createVitafContentView(): View {
        binding = VitafDlogTipsBinding.inflate(LayoutInflater.from(context))
        return binding.root
    }

    override fun initializeVitafViews() {
    }

    override fun setupVitafEventListeners() {
        setOnClickListener(binding.buttonCancel) //取消
        setOnClickListener(binding.buttonConfirm) //ok
    }

    override fun loadVitafData() {
    }

    override fun onVitafEventViewClick(v: View?) {
        dismiss()
        if(mCallback != null){
            mCallback?.onClick(v)
        }
    }

    /**
     * 设置埋点备注
     */
    fun addGombeCreditKindTipsEventRemark(remark: String){
        pageRemark = remark
    }

    /**
     * 设置提示图标
     */
    fun setGombeCreditKindTipsIconResource(resId: Int){
        binding.imgKindIcon.setImageResource(resId)
    }

    /**
     * 设置提示title
     */
    fun setGombeCreditKindTipsTitleText(title: String){
        binding.textKindTitle.text = title
    }

    /**
     * 设置提示title
     */
    fun setGombeCreditKindTipsTitleText(title: String, color: Int){
        setGombeCreditKindTipsTitleText(title)
        binding.textKindTitle.setTextColor(color)
    }

    /**
     * 设置提示语
     */
    fun setGombeCreditKindTipsMsgText(tips: String){
        binding.textKindTips.text = tips
    }

    /**
     * 设置提示语
     */
    fun setGombeCreditKindTipsMsgText(spannableString: SpannableString){
        binding.textKindTips.text = spannableString
    }

    /**
     * 设置提示语对齐方式
     */
    fun setGombeCreditKindTipsMsgGravity(gravity: Int){
        binding.textKindTips.gravity = gravity
    }

    /**
     * 设置显示一个按钮或两个按钮
     */
    fun isGombeCreditKindTipsDoubleButton(isDouble: Boolean){
        if (isDouble){//显示两个按钮
            binding.buttonCancel.visibility = View.VISIBLE
            binding.buttonConfirm.visibility = View.VISIBLE
        } else {
            binding.buttonCancel.visibility = View.GONE
            binding.buttonConfirm.visibility = View.VISIBLE
        }
    }

    /**
     * 设置取消文字
     */
    fun setGombeCreditKindTipsButtonCancelText(text: String){
        binding.buttonCancel.text = text
    }

    /**
     * 设置取消按钮背景
     */
    fun setGombeCreditKindTipsButtonCancelBackgroundResource(color: Int){
        binding.buttonCancel.getShapeDrawableBuilder().setSolidColor(color).intoBackground()
    }

    /**
     * 设置ok文字
     */
    fun setGombeCreditKintTipsButtonConfirmText(text: String){
        binding.buttonConfirm.text = text
    }

    /**
     * 设置ok按钮背景
     */
    fun setGombeCreditKindTipsButtonConfirmBackgroundResource(color: Int){
        binding.buttonConfirm.getShapeDrawableBuilder().setSolidColor(color).intoBackground()
    }

    /**
     * 设置两个按钮背景
     */
    fun setGombeCreditKindTipsButtonDoubleBackgroundResource(cancelColor: Int, okColor: Int){
        binding.buttonCancel.getShapeDrawableBuilder().setSolidColor(cancelColor).intoBackground()
        binding.buttonConfirm.getShapeDrawableBuilder().setSolidColor(okColor).intoBackground()
    }

    interface IDialogCallback {
        //按钮点击
        fun onClick(view: View?)
    }
}